package cn.xmy.demo01.servlet;

import cn.xmy.demo01.pojo.Address;
import cn.xmy.demo01.service.AddressService;
import cn.xmy.demo01.service.impl.AddressServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;


import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

@WebServlet("/findDefaultAddressServlet")
public class FindDefaultAddressServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        AddressService addressService=new AddressServiceImpl();
        List<Address> addresses=null;
        List<Address> addresses1=null;
        try {
            addresses=addressService.findDefaultAddress();
            addresses1=addressService.findAllAddress();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        request.setAttribute("addresses", addresses);
        request.setAttribute("addresses1", addresses1);
        request.getRequestDispatcher("sureOrder.html").forward(request, response);

    }
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }
}